package com.wanmait.myhouse.managerController;
import com.wanmait.myhouse.dao.FeedBackDAO;
import com.wanmait.myhouse.dao.MediatorDAO;
import com.wanmait.myhouse.dao.UserDAO;
import com.wanmait.myhouse.vo.FeedBack;
import com.wanmait.myhouse.vo.Mediator;
import com.wanmait.myhouse.vo.User;
import org.apache.taglibs.standard.extra.spath.Step;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("manager")
public class ManagerSystemController {

    @PostMapping("reply")
    public String reply(FeedBack feedBack){
        feedBack.setDispose(true);
        FeedBackDAO feedBackDAO = new FeedBackDAO();
        feedBackDAO.updateById(feedBack);
        return "redirect:/manager/userFeedBack";
    }
    @GetMapping("system")
    public String system (FeedBack feedBack, Model model){
        FeedBackDAO feedBackDAO = new FeedBackDAO();
        FeedBack selectById = feedBackDAO.selectById(feedBack.getId());
        UserDAO userDAO = new UserDAO();
        User user = userDAO.findById(feedBack.getUserId());
        selectById.setUser(user);
        if (feedBack.getMediatorId() != null || "".equals(feedBack.getMediatorId())){
            MediatorDAO mediatorDAO = new MediatorDAO();
            Mediator mediator = mediatorDAO.findById(feedBack.getMediatorId());
            selectById.setMediator(mediator);
        }
        model.addAttribute("feedBack",selectById);
        return "manager/system";
    }
}
